package cn.snowsoft.iot.module.cps.controller.admin.monitoring;


import cn.snowsoft.iot.framework.common.pojo.CommonResult;
import cn.snowsoft.iot.module.cps.constant.CpsConstant;
import cn.snowsoft.iot.module.cps.controller.admin.monitoring.vo.SearchParamVO;
import cn.snowsoft.iot.module.cps.service.monitoring.IMonitoringService;
import cn.snowsoft.iot.module.cps.utils.IpUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
@RequestMapping("/cps/monitoring")
@Tag(name = "管理后台 - 数采监控信息接口")

public class MonitoringController {
    private final IMonitoringService monitoringService;

    public final IpUtil ipUtil;
	@Value("${server.port:}")
	public String port;




    @GetMapping("/selectData")
    @ApiOperationSupport(order = 17)
    @Operation(summary = "今日，本周，本月，开始到结束")
    public CommonResult selectData(SearchParamVO searchParamVO) throws IOException {
        return CommonResult.success(monitoringService.cardDate(searchParamVO));
    }

    @GetMapping("/selectDataHistoryStatistic")
    @ApiOperationSupport(order = 17)
    @Operation(summary = "今日，本周，本月，开始到结束")
    public CommonResult selectDataHistoryStatistic(SearchParamVO searchParamVO) throws IOException {
        return CommonResult.success(monitoringService.selectDataHistoryStatistic(searchParamVO));
    }

    @PostMapping("/ipUtil")
    @ApiOperationSupport(order = 18)
    @Operation(summary = "获取本机地址")
    public CommonResult ipUtil() throws Exception {
        return CommonResult.success("ws://" + ipUtil.getLocalIP() +":"+port+ CpsConstant.WEBSCOKET);
    }


}
